package com.kb.design.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kb.design.common.ApiResponse;
import com.kb.design.common.ResponseObject;
import com.kb.design.entity.CustomUser;
import com.kb.design.entity.DesignRole;
import com.kb.design.entity.DesignTalk;
import com.kb.design.service.DesignRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色信息表(DesignRole)表控制层
 *
 * @author makejava
 * @since 2024-01-17 15:31:33
 */
@RestController
@RequestMapping("/role")
public class DesignRoleController {
    @Autowired
    private DesignRoleService designRoleService;

    /**
     * 分页查询所有数据
     *
     * @param
     * @param designRole 查询实体
     * @return 所有数据
     */
    @PostMapping("/pageList")
    public ApiResponse pageList(@RequestBody DesignRole designRole) {
        Page<DesignRole> page = new Page<>(designRole.getPage(), designRole.getPerPage());
        ResponseObject responseObject = new ResponseObject();

        Page<DesignRole> designTalkPage = designRoleService.pageList(page, designRole);
        responseObject.setItems(designTalkPage.getRecords());
        responseObject.setTotal(designTalkPage.getTotal());
        return ApiResponse.success(responseObject);
    }
    /**
     *
     * @param
     * @return
     */
    @PostMapping("/save")
    public ApiResponse saveBonusConfig(@RequestBody DesignRole designRole) {
        return ApiResponse.success(designRoleService.save(designRole));
    }

    /**
     * 页面显示用户角色与部门
     * @param customUser
     * @return
     */
    @PostMapping("/queryRoleByCode")
    public ApiResponse queryRoleByCode(@RequestBody CustomUser customUser) {
        return ApiResponse.success(designRoleService.queryRoleByCode(customUser.getCode()));
    }
    /**
     * 删除
     * @param
     * @return
     */
    @GetMapping("/remove")
    public ApiResponse remove(Long roleId){
        return ApiResponse.success(designRoleService.deleteDeptById(roleId));
    }
}
